package com.blrs.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.annotation.RepeatSubmit;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.domain.IndexCollection;
import com.blrs.service.indexInfo.IInfoIndexService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.InfoIndex;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 首页信息服务Controller
 * 
 * @author ruoyi
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/system/index")
public class InfoIndexController extends BaseController
{
    @Autowired
    private IInfoIndexService infoIndexService;

    /**
     * 查询首页信息服务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(InfoIndex infoIndex)
    {
        startPage();
        infoIndex.setOrgId(SecurityUtils.getOrgId());
        List<InfoIndex> list = infoIndexService.selectInfoIndexList(infoIndex);
        return getDataTable(list);
    }
    /**
     * 所有信息(平台端发送的数据)
     */
    @GetMapping("/selfList")
    public TableDataInfo adminList(InfoIndex infoIndex){
        startPage();
        //infoIndex.setOrgId(100l);
        List<InfoIndex> list =infoIndexService.selectInfoIndexList(infoIndex);
        return getDataTable(list);
    }

    /**
     * 导出首页信息服务列表
     */
    @Log(title = "首页信息服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoIndex infoIndex)
    {
        List<InfoIndex> list = infoIndexService.selectInfoIndexList(infoIndex);
        ExcelUtil<InfoIndex> util = new ExcelUtil<InfoIndex>(InfoIndex.class);
        util.exportExcel(response, list, "首页信息服务数据");
    }

    /**
     * 获取公共端信息服务的详情信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(infoIndexService.selectInfoIndexById(id));
    }

    /**
     * 新增首页信息服务
     */
    @Log(title = "首页信息服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoIndex infoIndex)
    {
        return toAjax(infoIndexService.insertInfoIndex(infoIndex));
    }

    /**
     * 查询收藏夹数据
     */
    @GetMapping("/getCollectionList")
    public List<InfoIndex> getIndexList(){
      return infoIndexService.selectInfoIndexListCollection();
    }


    /**
     * 收藏信息
     */
    @PostMapping("/info")
    @RepeatSubmit(interval = 3000,message = "请勿重复点击")
    public AjaxResult collectionInfo(@RequestBody InfoIndex infoIndex) throws IOException, NoSuchFieldException, IllegalAccessException {
      return toAjax(infoIndexService.collectionInfo(infoIndex));
    }
    /**
     * 取消收藏
     */
    @PostMapping("/noInfo")
    @RepeatSubmit(interval = 3000,message = "请勿重复点击")
    public AjaxResult collectionNoInfo(@RequestBody InfoIndex infoIndex){
        return  toAjax(infoIndexService.collectionNoInfo(infoIndex));
    }

    /**
     * 修改首页信息服务
     */
    @Log(title = "首页信息服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoIndex infoIndex)
    {
        return toAjax(infoIndexService.updateInfoIndex(infoIndex));
    }

    /**
     * 删除首页信息服务
     */
    @Log(title = "首页信息服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(infoIndexService.deleteInfoIndexByIds(ids));
    }






}
